package com.zero.spring.rabbitmq;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:spring-rabbitmq-producer.xml")
public class Producer {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @Test
    public void simpleModeSendMessage(){
        rabbitTemplate.convertAndSend("spring_queue","hello world spring....");
        System.out.println("Simple mode send complete.");
    }

    @Test
    public void fanoutModeSendMessage(){

        /**
         * @param1 exchange,
         * @param2 routingKey,
         * @param3 Message
         */
        rabbitTemplate.convertAndSend("spring_fanout_exchange","","spring fanout...");
        System.out.println("Fanout Exchange send complete.");
    }

    /**
     * routing
     */
    @Test
    public void directModeSendMessage(){
        rabbitTemplate.convertAndSend("spring_direct_exchange","info","spring direct...");
        System.out.println("Direct Exchange send complete.");
    }

    @Test
    public void topicModeSendMessage(){
        rabbitTemplate.convertAndSend("spring_topic_exchange","zero.wql","spring topic...");
        rabbitTemplate.convertAndSend("spring_topic_exchange","zero.wql.hello","spring topic1...");
        rabbitTemplate.convertAndSend("spring_topic_exchange","zerowql.wql.hello","spring topic2...");
        System.out.println("topic Exchange send complete.");
    }

}
